package edu.hitsz.aircraft;

import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.basic.AbstractFlyingObject;
import edu.hitsz.aircraft.shoot.ShootStrategy;
import edu.hitsz.aircraft.shoot.StraightShoot;

import java.util.List;

/**
 * 所有种类飞机的抽象父类：
 * 敌机（BOSS, ELITE, MOB），英雄飞机
 *
 * @author hitsz
 */
public abstract class AbstractAircraft extends AbstractFlyingObject {
    /**
     * 生命值
     */
    protected int maxHp;
    protected int hp;
    // 攻击方式
    /**
     * 射击策略
     */
    protected ShootStrategy shootStrategy;
    /**
     * 子弹一次发射数量, 不想发射子弹把shootNum设置为0即可
     */
    protected int shootNum;
    /**
     * 子弹伤害
     */
    protected int power;
    /**
     * 子弹射击方向 (向下发射：1，向上发射：-1)
     */
    protected int shootDirection;

    public AbstractAircraft(int locationX, int locationY, int speedX, int speedY, int hp,
                            int shootNum, int power, int shootDirection) {
        super(locationX, locationY, speedX, speedY);
        this.hp = hp;
        this.maxHp = hp;
        this.shootNum = shootNum;
        this.power = power;
        this.shootDirection = shootDirection;
        this.shootStrategy = new StraightShoot();
    }

    public void decreaseHp(int decrease) {
        hp -= decrease;
        if (hp <= 0) {
            hp = 0;
            vanish();
        }
    }

    public int getHp() {
        return hp;
    }

    public void setShootNum(int shootNum){
        if (shootNum > 0) {
            this.shootNum = shootNum;
        }
    }

    public int getShootNum(){
        return this.shootNum;
    }

    public void setPower(int power) {
        this.power = power;
    }

    public int getPower() {
        return power;
    }

    public void setShootDirection(int shootDirection) {
        this.shootDirection = shootDirection;
    }

    public int getShootDirection(){
        return shootDirection;
    }

    public void setShootStrategy(ShootStrategy shootStrategy) {
        this.shootStrategy = shootStrategy;
    }

    /**
     * 飞机射击方法，可射击对象必须实现
     *
     * @return 可射击对象需实现，返回子弹
     * 非可射击对象空实现，返回null
     */
    public List<BaseBullet> shoot(){
        return shootStrategy.shoot(this);
    }

}


